<script setup>
import { ref,onMounted } from 'vue'
import { queryWarehousingEntryUp,updateWarehousingEntryUp } from '../../api/warehousingentryup'
import { queryAllWarehouseAreaLocal } from '../../api/warehousearealocal'
import { ElMessage } from 'element-plus'

//定义库位集合
const warehouseAreaLocalList = ref([])
//查询所有库位
const getwarehouseAreaLocalList = async ()=>{ 
  const result = await queryAllWarehouseAreaLocal()
  warehouseAreaLocalList.value = result.data
}

//定义弹出框数据
const title = ref(null)
const dialogShow = ref(false)
const dialogData = ref({localCode:'',count:''})

//定义表单数据
const warehousingEntryUpFrom = ref({ supplierName: ''})
//定义表单数据
const warehousingEntryUpList = ref([])
//条件查询的点击事件
const query = async ()=>{ 
  const result = await queryWarehousingEntryUp(page.value,pageSize.value,warehousingEntryUpFrom.value.supplierName)
  warehousingEntryUpList.value = result.data.rows
  total.value = result.data.total
}
//清空表单数据
const clear = ()=>{
  warehousingEntryUpFrom.value = {supplierName:''}
  query()
}

//定义分页的变量
const page = ref(1)
const pageSize = ref(10)
const total = ref(0)
//定义分页的点击事件
const handleSizeChange = (val) => {
  page.value = 1
  query()
}
const handleCurrentChange = (val) => {
  query()
}

//回显数据
const edit = async (id)=>{
  title.value = '上架'
  dialogShow.value = true
  //清空对话框数据
  dialogData.value = {localCode:'',count:''}
  countData.value.id = id
}

//定义上架接收的变量
const countData = ref({id:'',localCode:'',count:''})

//确定上架的点击事件
const confirmeUpInfo = async () =>{ 
  countData.value.localCode = dialogData.value.localCode
  countData.value.count = dialogData.value.count
  const result = await updateWarehousingEntryUp(countData.value)
  if(result.code){
    ElMessage.success('操作成功')
    query()
    dialogShow.value = false
    countData.value = {id:'',localCode:'',count:''}
  }else{
    ElMessage.error('操作失败！请重新操作')
  }
}

//挂载
onMounted(() => {
  getwarehouseAreaLocalList()
  query()
})
</script>

<template>
<div><h4>待上架</h4></div>

<div>
  <el-form :inline="true" :model="warehousingEntryUpFrom" class="demo-form-inline">
    <el-form-item>
      <el-input v-model="warehousingEntryUpFrom.supplierName" placeholder="供应商名称" style="width: 200px;"/>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="query" plain>查询</el-button>
      <el-button type="default" @click="clear" plain>清空</el-button>
    </el-form-item>
  </el-form>
</div>

<!-- table表格 -->
<div>
  <el-table :data="warehousingEntryUpList" border style="width: 100%" >
    <el-table-column fixed type="index" label="序号" align="center"  width="80"/>
    <el-table-column prop="batchNumber" label="批次号" align="center" width="120"/>
    <el-table-column prop="skuNumber" label="商品编号" align="center" width="120"/>
    <el-table-column prop="supplierName" label="供应商名称" align="center" width="180"/>
    <el-table-column prop="title" label="商品名称" align="center" width="200"/>
    <el-table-column prop="price" label="商品价格" align="center" width="120"/>
    <el-table-column prop="pickingNumber" label="分拣总数量" align="center" width="120"/>
    <el-table-column prop="count" label="上架数量" align="center" width="120"/>
    <el-table-column prop="consignorName" label="货主名称" align="center"  width="200"/>
    <el-table-column fixed="right" label="操作" align="center" width="120">
      <template #default="scope">
        <el-button size="small" type="success" @click="edit(scope.row.id)" plain><el-icon><Upload /></el-icon></el-button>
      </template>
    </el-table-column>
  </el-table>
</div>

<!-- 分页 -->
<div>
  <el-pagination
  v-model:current-page="page"
  v-model:page-size="pageSize"
  :page-sizes="[5, 10, 15, 20]"
  layout="total, sizes, prev, pager, next, jumper"
  :total="total"
  @size-change="handleSizeChange"
  @current-change="handleCurrentChange"/>
</div>

<!-- 弹出框 -->
<div>
  <el-dialog v-model="dialogShow" :title="title" width="500" align-center>
    <el-form :model="dialogData">
      <el-form-item>
        <el-select v-model="dialogData.localCode" placeholder="请选择库位" style="width: 350px;">
          <el-option v-for="item in warehouseAreaLocalList" :label="item.localCode" :value="item.id" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dialogData.count" placeholder="输入上架的数量" style="width: 350px;"/>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="dialogShow = false" type="default">取消</el-button>
      <el-button type="primary" @click="confirmeUpInfo" plain>确定</el-button>
    </template>
  </el-dialog>
</div>
</template>
<style scoped>
</style>